package sctu.edu.java.year2016.team04.yanghuilin.day20160605.chapter11_1;

/**
 * Created by dell on 2016/6/5.
 * 编写一个异常类MyException,再编写一个Student类，该类有一个产生异常的speak(int m)方法。要求参数m的值大于1000时，
 * 方法抛出一个MyException对象。最后编写主类，在主方法中创建Student对象，让该对象调用speak()方法。
 */
public class Unusual extends Exception {
    public static void main(String[] args) {
        Student student = new Student();
        try {
            student.speak(10000);
        } catch (MyException ex) {
            System.out.println("输入错误，数字应该不大于1000");
        }

    }
}


class MyException extends Exception {
    String message;

    public MyException(int m) {
        message = "数字m应该不大于1000";
    }

    public String toString() {
        return message;
    }
}


class Student extends Exception {
    public void speak(int m) throws MyException {
        if (m > 1000) {
            throw new MyException(m);
        } else
            System.out.println(m);
    }
}
